<?php

namespace Managers;

class CTemplates extends \Lib\Model\DoctrineManager{

    
    public function saveToBase($ctArrays) {
        $em = $this->getEntityManager();
        $em->getConnection()->beginTransaction();
        try {
            foreach($ctArrays as $key=>$categoryArr){
                
                foreach($categoryArr as $inKey=>$template){
                    $abbr = $template->getAbbreviation();
                    $template->setAbbreviation($abbr[0]);
                    if(!$template->getRank()) $template->setRank(1);
                    if(!$template->getCreatedAt()) $template->setCreatedAt(new \DateTime());
                    
                    print_r($template);
                    $em->persist($template);
                }                
            }
            $em->flush();
            $em->commit();
            
        } catch (Exception $exc) {
            $em->getConnection()->rollback();
        }
        
        
        
        
    }
    
}